package com.example.boardroom.demo;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.impl.LoadingPopupView;

public class BaseActivity extends AppCompatActivity {

    private LoadingPopupView loadingPopupView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
    }


    public void showLoadingView(boolean b, String title) {
        if (loadingPopupView == null) {
            if (TextUtils.isEmpty(title)) {
                loadingPopupView = new XPopup.Builder(this)
                        .dismissOnBackPressed(b) // 按返回键是否关闭弹窗，默认为true
                        .dismissOnTouchOutside(b) // 点击外部是否关闭弹窗，默认为true
                        .asLoading();
            } else {
                loadingPopupView = new XPopup.Builder(this)
                        .dismissOnBackPressed(b) // 按返回键是否关闭弹窗，默认为true
                        .dismissOnTouchOutside(b) // 点击外部是否关闭弹窗，默认为true
                        .asLoading(title);
            }
        }
        loadingPopupView.show();
//        if (loadingView != null) {
//            loadingView.setVisibility(View.VISIBLE);
//            if (!TextUtils.isEmpty(title)) {
//                ((TextView) loadingView.findViewById(R.id.tv_title)).setVisibility(View.VISIBLE);
//                ((TextView) loadingView.findViewById(R.id.tv_title)).setText(title);
//            } else {
//                ((TextView) loadingView.findViewById(R.id.tv_title)).setVisibility(View.GONE);
//            }
//            loadingView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    if (b) {
//                        loadingView.setVisibility(View.GONE);
//                    }
//                }
//            });
//        }
    }


    public void hideLoadingView() {

        if (loadingPopupView != null && loadingPopupView.isShow()) {
            loadingPopupView.dismiss();
        }
//        if (loadingView != null) {
//            loadingView.setVisibility(View.GONE);
//        }

    }

}
